import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/api'
import addresses from '@/api/addresses'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		store: {}, // 
		appProperties: {
			"shopName": "润土刺茶",
			"sendingPrice": 100, // 外卖配送费
			"packingPrice": 0, // 包装费
			"seedingNeedLeastPrice": 1000 // 起送需要的最低价格
		}, // 相关信息 比如配送费
		// cart: [],
		addresses: addresses,
		member: {},
		
		
		order: {},
		userInfo: null,
		address: {
			dorm: '',
			detail: ''
		},
		takeType: '外卖配送', // 取餐方式
		token: null
	},
	getters: {
		getUserInfo: state => {return state.userInfo; },
		getToken: state => {return state.token},
		getTakeType: state => {return state.takeType}
	},
	mutations: {

		SET_MEMBER(state, member) {
			state.member = member
		},

		SET_ADDRESSES(state, addresses) {
			state.addresses = addresses
		},
		SET_STORE(state, store) {
			state.store = store
		},
		// SET_CART(state, cart) {
		// 	state.cart = cart
		// },
		REMOVE_CART(state) {
			state.cart = []
		},
		SET_ORDER(state, order) {
			state.order = order
		},
		
		
		login(state, userInfo) {
			console.log("[vuex] 登录", userInfo)
			state.hasLogin = true;
			state.userInfo = userInfo;
			state.token = userInfo.token;
			uni.setStorageSync('token', userInfo.token)
		},
		logout(state) {
			console.log("[vuex] 退出登录")
			state.hasLogin = false;
			state.userInfo = null;
			state.token = null;
			uni.removeStorageSync('token');
		},
		setUserInfo(state, userInfo){
			state.userInfo = userInfo;
		},
		setToken(state, token){
			state.token = token;
		},
		// 收获地址
		SET_ADDRESS(state, address) {
			state.address = address
		},
		// 订单信息
		set_order(state, order){
			state.order = order;
		},
		set_take_type(state, type) {
			state.takeType = type
		},
	},
	actions: {
	}
})

export default store